<template>
	<view class="content">
		<view class="top">
			<image mode="widthFix" :src="bookImage">
			</image>
		</view>
		<view class="center">
			<view class="name">{{bookname}}</view>
			<view class="bookinfo" v-if="bookinfo">描述: {{bookinfo}}</view>
			<view class="price">期望￥{{price}}</view>
			<view class="ibsn">ISBN:{{ISBN}}</view>
		</view>
		<view class="bottombar">
			<view class="zhuye" @click="goTopage1">
				<image class="img11" :src="avatar" mode="aspectFill"></image>
			</view>
			<view class="lianxi" @click="goToConnect">
				<view class="iconfont icon-xiaoxi"></view>
				<view class="title">联系</view>
			</view>
		</view>
	</view>

</template>
<script>
	export default {
		data() {
			return {
				id: '',
				userId: '',
				username: '',
				bookname: '',
				bookImage: '',
				bookinfo: '',
				ISBN: '',
				price: '',
				avatar: '',
				originAvatar: '',
			}
		},
		onLoad() {
			this.init()
		},
		components: {},
		methods: {
			async init() {
				try {
					const page = await getCurrentPages()
					let x = page.length - 1
					let ImgUrl = getApp().globalData.ImgUrl
					let options = page[x].options
					this.userId = options.userId
					this.id = options.id
					this.username = options.username
					this.avatar = ImgUrl + options.avatar
					this.originAvatar = options.avatar
					this.getBookInfo()
				} catch (res) {
					// console.log(res)
				}
			},
			getBookInfo() {
				let id = Number(this.id)
				let userId = Number(this.userId)
				let ImgUrl = getApp().globalData.ImgUrl
				let BaseUrl = getApp().globalData.BaseUrl
				let token = uni.getStorageSync('token');
				uni.request({
					url: BaseUrl + '/purchase/detail',
					header: {
						'Content-Type': 'application/json',
						'token': token
					},
					data: {
						userId: userId,
						id: id
					},
					success: (res) => {
						// console.log("bookinfo", res)
						let data = res.data.data
						this.bookname = data.purchaseBook.bookName
						this.bookImage = ImgUrl + data.purchaseImage
						this.ISBN = data.purchaseBook.ibsn
						this.price = data.expectPrice
						this.bookinfo = data.describe
					}
				})
			},
			goTopage1() {
				uni.navigateTo({
					url: '/pages/Personal/Personal?userId=' + this.userId + '&avatar=' + this.originAvatar +
						'&username=' + this.username
				})
			},
			goToConnect() {
				uni.navigateTo({
					url: '../xiaoxi/chatDetail?toId=' + this.userId + '&toName=' + this.username + '&toAvatar=' +
						this.originAvatar
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;

		.top {
			width: 90%;
			height: 500upx;
			background-color: #888;
			display: flex;
			justify-content: center;
			align-items: center;
			box-shadow: 0 0 10upx #888888;
			border-radius: 20upx;
			overflow: hidden;
			margin-top: 15upx;
		}

		.center {
			position: absolute;
			top: 520upx;
			left: 60upx;

			.name {
				font-size: 36upx;
				font-weight: bold;
			}

			.price {
				position: relative;
				top: 5upx;
				color: tomato;
				font-size: 38upx;
				font-weight: bold;
			}
		}


		.bottombar {
			// margin-top: 120upx;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 100upx;
			background-color: #fff;
			box-shadow: 0 0 15upx #888;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.zhuye {
				.img11 {
					border-radius: 50upx;
					width: 70upx;
					height: 70upx;
				}
			}

			.lianxi {
				position: relative;
				left: 30upx;

				.title {
					position: relative;
					top: -2upx;
					font-size: 25upx;
				}
			}

		}
	}
</style>
